package com.atguigu.algorithm;

import java.util.Scanner;

public class ThroughTheMaze {
    public static int ans=Integer.MAX_VALUE;
    public static void findTheStep(char[][] map,int x,int y,int cur,int ans){
        if( x<0 || x>9 || y<0 || y>9 || map[x][y]=='#'){
            return;
        }
        if(cur>ans){
            return;
        }
        if(x==9 && y==8){
            if(ans>cur){
                ans=cur;
                return;
            }
        }
        map[x][y]='#';
        findTheStep(map,x,y+1,cur+1,ans);
        findTheStep(map,x,y-1,cur+1,ans);
        findTheStep(map,x+1,y,cur+1,ans);
        findTheStep(map,x-1,y,cur+1,ans);
        map[x][y]='.';
    }
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while(scanner.hasNext()){
            char[][] map=new char[10][10];
            for(int i=0;i<10;i++){
                String s=scanner.next();
                for(int j=0;j<10;j++){
                    map[i][j]=s.charAt(j);
                }
            }
            ans=Integer.MAX_VALUE;
            //map初始化成功，进行走迷宫
            findTheStep(map,0,1,0,ans);
            System.out.println(ans);
        }
    }
}
